/**	
 * <br>
 * Copyright 2011 Chuan. All rights reserved.<br>
 * <br>			 
 * Package: com.chuan.mantu.service <br>
 * FileName: LocalPicService.java <br>
 * <br>
 * @version
 * @author javacyc@qq.com
 * @created 2012-11-20
 * @last Modified 
 * @history
 */

package com.chuan.mantu.service;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;

import android.content.Context;
import android.os.Environment;

import com.chuan.mantu.utils.Const;
import com.chuan.mantu.utils.FileUtil;
import com.chuan.mantu.vo.Pic;

/**
 * {初始化图片Service}
 *  
 *  @author javacyc@qq.com
 *  @created 2012-11-20 上午10:39:31
 *  @lastModified       
 *  @history           
 */

public class LocalPicService {

	/**
	 * 
	 *  ｛初始化类别下的Pic集合｝
	 *  @param context 当前Activity 对象
	 *  @param category 当前类别
	 *  @return Pic集合
	 *  @author javacyc@qq.com
	 *  @created 2012-11-20 上午10:50:18
	 *  @lastModified       
	 *  @history
	 */
	public static LinkedList<ArrayList<Pic>> initPicList(Context context, String category) {
		String rootPath =	Environment.getExternalStorageDirectory().getAbsolutePath()
								+ Const.PATH_BACKLASH
								+ Const.SDCARD_FILENAME
								+ Const.PATH_BACKLASH
								+ Const.PIC_ROOT_PATH
								+ Const.PATH_BACKLASH
								+ category
								+ Const.PATH_BACKLASH;
		File file = new File(rootPath);
		LinkedList<ArrayList<Pic>> lap = new LinkedList<ArrayList<Pic>>();
		if(file.list().length == 0){ //空文件夹，从网络更新数据
			NetPicService.updatePicList(context,file,category);
		}
		lap.add(FileUtil.getPicArrayList(file,category));
		return lap;
	}
	
	
	/**
	 * 
	 *  ｛获取历史数据中的图片集合｝
	 *  @param category
	 *  @return
	 *  @author javacyc@qq.com
	 *  @created 2012-11-20 下午02:34:34
	 *  @lastModified
	 *  @history
	 */
	public static ArrayList<Pic> getHisPicList(String category){
		String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath()
									+ Const.PATH_BACKLASH  
									+ Const.SDCARD_FILENAME
									+ Const.PATH_BACKLASH 
									+ Const.PIC_ROOT_PATH 
									+ Const.PATH_BACKLASH 
									+ category 
									+ Const.PATH_BACKLASH;
		File file = new File(rootPath);
		return FileUtil.getHisPicArrayList(file,category);
	}
	
	
}